package com.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.bean.bo.DeviceInfo;
import com.util.RandomUtil;

@RestController
public class DeviceDataController {
	private List<DeviceInfo> devices = new ArrayList<>();

	@GetMapping("/api/devices")
	public List<DeviceInfo> getDeviceInfo() {
		if (devices.isEmpty()) {
			for (int i = 0; i < 6; i++) {
				DeviceInfo deviceInfo = new DeviceInfo(i + "", RandomUtil.generateString(4), "SLA", "20-1000mm",
						"1000w", RandomUtil.getRandomPercent());
				devices.add(deviceInfo);
			}
			return devices;
		}
		for (DeviceInfo deviceInfo : devices) {
			int percent=deviceInfo.getPercent();
			if (percent>=100) {
				deviceInfo.setPercent(percent+1);
			}
		}
		return devices;
	}
}
